package com.longyou.gateway.filter;

import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Mono;

@Component
public class RemoveHeaderGatewayFilterFactory extends AbstractGatewayFilterFactory<RemoveHeaderGatewayFilterFactory.Config> {

    public RemoveHeaderGatewayFilterFactory() {
        super(Config.class);
    }
    @Override
    public GatewayFilter apply(Config config) {
        return (exchange, chain) -> chain.filter(exchange).then(Mono.fromRunnable(() -> {
            ServerHttpResponse response = exchange.getResponse();
            response.getHeaders().remove("WWW-Authenticate");
        }));
    }

    public static class Config {
        // Put any needed configuration here
    }
}
